package com.radon.controller;

import com.alibaba.fastjson.JSONObject;
import com.radon.entity.DemoDO;
import com.radon.service.DemoService;
import com.radon.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * demo 接口
 *
 * @RestController返回json的Controller
 */
@RestController
@CrossOrigin(origins = "*", maxAge = 3600)  //开启跨域
@RequestMapping("demo")
public class DemoApi {
    /**
     * 注入serivice
     */
    @Autowired
    private DemoService demoService;

    /**
     * 新增
     * @param demoDO
     * @return
     */
    @PostMapping("add")
    public Result add(DemoDO demoDO){
        demoService.save(demoDO);
        return Result.success("success",null);
    }

    /**
     * 获取
     * @param id
     * @return
     */
    @GetMapping("get")
    public Result get(Long id){
        return Result.success("success",demoService.getById(id));
    }

    /**
     * 修改
     * @param demoDO
     * @return
     */
    @PutMapping("upd")
    public Result upd(DemoDO demoDO){
        demoService.updateById(demoDO);
        return Result.success("success",null);
    }

    @PutMapping("del")
    public Result del(Long id){
        demoService.removeById(id);
        return Result.success("success",null);
    }

}
